import { Result, Icon, Spin } from 'antd';
import React, { PureComponent } from 'react';

export default class Empty extends PureComponent {
  judgeEmptyTitleState = emptyTitle => {
    let node;
    let icon;
    if (
      emptyTitle === false ||
      emptyTitle === null ||
      emptyTitle.indexOf('暂无') > -1 ||
      emptyTitle.indexOf('不存在') > -1 ||
      emptyTitle.indexOf('失败') > -1 ||
      emptyTitle.indexOf('无法') > -1
    ) {
      node = emptyTitle;
      icon = <Icon type="folder-open" style={{ color: '#ccc' }} theme="filled" />;
    } else {
      node = <Spin tip={emptyTitle} />;
      icon = <></>;
    }

    return { node, icon };
  };

  render() {
    const { emptyTitle } = this.props;
    return (
      <Result
        icon={this.judgeEmptyTitleState(emptyTitle).icon}
        subTitle={this.judgeEmptyTitleState(emptyTitle).node}
      />
    );
  }
}
